<template>
  <div>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="贴子标题">
        <el-input
          clearable
          size="small"
          v-model="formInline.content"
          auto-complete="off"
          placeholder="请输入贴子标题"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getData">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      size="small"
      :data="datalist"
      highlight-current-row
      border
      element-loading-text="拼命加载中"
      style="width: 100%;"
    >
      <el-table-column align="center" sortable prop="title" label="标题" min-width="200"></el-table-column>
      <el-table-column align="center" sortable prop="content" label="内容" min-width="200"></el-table-column>
      <el-table-column align="center" sortable prop="createAccount" label="发布人" min-width="150"></el-table-column>
      <el-table-column align="center" sortable prop="status" label="状态" width="100">
        <template slot-scope="scope">{{scope.row.status == 0 ? '正常':'封禁'}}</template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 0"
            size="mini"
            type="danger"
            @click="del(scope.row,2)"
          >封禁</el-button>
          <el-button v-else size="mini" type="primary" @click="del(scope.row,0)">解除封禁</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="page-box"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      background
      :current-page="pageparm.currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageparm.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageparm.total"
    ></el-pagination>
  </div>
</template>
  <script type="text/ecmascript-6">
import { getList,delMessage } from "../../api/tiezi";
export default {
  data() {
    return {
      formInline: {},
      datalist: [],
      pageparm: {
        currentPage: 0,
        pageSize: 10,
        total: 0
      },
      dialogVisible: false,
      addData: {}
    };
  },
  created() {
    this.getData();
  },
  methods: {
    del(row, type) {
      let param = {};
      param.status = type;
      param.id = row.id;
      delMessage(param).then(res => {
        if (res.status == 200) {
          this.$message({
            type: "success",
            message: "操作成功"
          });
        } else {
          this.$message({
            type: "error",
            message: "删除失败"
          });
        }
        this.getData();
      });
    },
    handleCurrentChange(val) {
      this.pageparm.currentPage = val;
      this.getData();
    },
    handleSizeChange(val) {
      this.pageparm.pageSize = val;
      this.getData();
    },
    getData() {
      this.formInline.pageIndex = this.pageparm.currentPage;
      this.formInline.pageSize = this.pageparm.pageSize;
      getList(this.formInline).then(res => {
        if (res.status == 200) {
          this.datalist = res.data;
          this.pageparm.total = res.total;
        }
      });
    }
  }
};
</script>